<?php
/**
 * Created by PhpStorm.
 * User: 牛赞赞
 * Date: 2021/3/27
 * Time: 15:27
 */

namespace App\Model;


class UserGameTimes extends Model
{
    protected   $table = 'user_game_times';
    protected   $fillable = ['id', 'uid','times','game_id','create_at','update_at'];
    public      $timestamps = false;

    public static function playTimes($uid){
        try{
            $data = self::query()->where('uid',$uid)->select('times','djs_times')->first();
            if(empty($data)){
                return ['code'=>2,'msg'=>'未查找到'];
            }
            return ['code'=>0,'data'=>$data->toArray()];
        }catch (\Exception $e){
            return ['code'=>1,'msg'=>$e->getMessage()];
        }
    }

    public static function updatePlayTimes($uid,$data){
        try{
            $data['update_at'] = time();
            self::query()->where('uid',$uid)->update($data);
            return ['code'=>0,'msg'=>'更新成功！'];
        }catch (\Exception $e){
            return ['code'=>1,'msg'=>$e->getMessage()];
        }
    }

    public static function insetRecord($data){
        try{
            self::query()->insert($data);
            return ['code'=>0,'msg'=>'添加成功！'];
        }catch (\Exception $e){
            return ['code'=>1,'msg'=>$e->getMessage()];
        }
    }

}